package com.rayboo.example.design.pattern.composite;

/**
 * 组合模式
 * http://c.biancheng.net/view/1373.html
 */
public class Main {

    public static void main(String[] args) {
        Employee ceo = new Employee("张三", "CEO", 30000);
        Employee salesManager = new Employee("李四", "销售部经理", 20000);
        Employee marketingManager = new Employee("王五", "市场部经理", 20000);
        Employee sale1 = new Employee("销售员工1", "销售员工", 10000);
        Employee sale2 = new Employee("销售员工2", "销售员工", 11000);
        Employee marketing1 = new Employee("市场员工1", "市场员工", 10000);
        Employee marketing2 = new Employee("市场员工2", "市场员工", 11000);
        Employee marketing3 = new Employee("市场员工3", "市场员工", 12000);

        salesManager.add(sale1);
        salesManager.add(sale2);
        marketingManager.add(marketing1);
        marketingManager.add(marketing2);
        marketingManager.add(marketing3);
        ceo.add(salesManager);
        ceo.add(marketingManager);

        System.out.println("张三管理的员工有：" + ceo.getSubordinateNames());
        System.out.println("李四管理的员工有：" + salesManager.getSubordinateNames());
        System.out.println("王五管理的员工有：" + marketingManager.getSubordinateNames());
        System.out.println("----------------");
        System.out.println("张三及其管理的员工总工资：" + ceo.getSubordinateTotalSalary());
        System.out.println("李四及其管理的员工总工资：" + salesManager.getSubordinateTotalSalary());
        System.out.println("王五及其管理的员工总工资：" + marketingManager.getSubordinateTotalSalary());
        System.out.println("----------------");
        System.out.println("销售员工1管理的员工有：" + sale1.getSubordinateNames());
        System.out.println("销售员工1及其管理的员工总工资：" + sale1.getSubordinateTotalSalary());
        System.out.println("----------------");
        marketingManager.remove(marketing1);
        System.out.println("市场员工1离职后");
        System.out.println("王五管理的员工有：" + marketingManager.getSubordinateNames());
        System.out.println("王五及其管理的员工总工资：" + marketingManager.getSubordinateTotalSalary());
    }
}
